{% from "dockers/dockerfile-macros.j2" import install_debian_packages, install_python_wheels, copy_files %}
ARG BASE=docker-config-engine-bookworm-{{DOCKER_USERNAME}}:{{DOCKER_USERTAG}}

FROM $BASE AS base

ARG docker_container_name
RUN [ -f /etc/rsyslog.conf ] && sed -ri "s/%syslogtag%/$docker_container_name#%syslogtag%/;" /etc/rsyslog.conf

## Make apt-get non-interactive
ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update        && \
    apt-get install -f -y    \
        libdbus-1-3          \
        libdbus-c++-1-0v5

{% if docker_sysmgr_debs.strip() -%}
# Copy locally-built Debian package dependencies
{{ copy_files("debs/", docker_sysmgr_debs.split(' '), "/debs/") }}

# Install locally-built Debian packages and implicitly install their dependencies
{{ install_debian_packages(docker_sysmgr_debs.split(' ')) }}
{%- endif %}

# creating sonic conig_status file.
RUN mkdir -p /var/sonic
RUN echo "# Config files managed by sonic-config-engine" > /var/sonic/config_status

COPY ["supervisord.conf", "/etc/supervisor/conf.d/"]
COPY ["critical_processes", "/etc/supervisor"]

FROM $BASE

RUN --mount=type=bind,from=base,target=/changes-to-image rsync -axAX --no-D --exclude=/sys --exclude=/proc --exclude=/dev --exclude=resolv.conf /changes-to-image/ /

## Make apt-get non-interactive
ENV DEBIAN_FRONTEND=noninteractive

ENTRYPOINT ["/usr/local/bin/supervisord"]
